﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace Toth.WLW.Plugins
{
    /// <summary>
    /// Interaction logic for BlogItemControl.xaml
    /// </summary>
    public partial class PingStatusControl : UserControl
    {
        private string _url;
        private string _errorMessage;

        public PingStatusControl(string blogTitle)
        {
            InitializeComponent();

            textBlockStatus.Text = "Posting to " + blogTitle + ".";
            imageError.Visibility = System.Windows.Visibility.Collapsed;
            imageSuccess.Visibility = System.Windows.Visibility.Collapsed;

        }

        public void ShowSuccess(string permalink)
        {
            textBlockStatus.Text += " Done!";
            imageSuccess.Visibility = System.Windows.Visibility.Visible;
            _url = permalink;
        }

        public void ShowError(string errorMessage)
        {
            textBlockStatus.Text += " Done!";
            imageError.Visibility = System.Windows.Visibility.Visible;
            _errorMessage = errorMessage;
        }

        private void imageError_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!string.IsNullOrEmpty(_errorMessage))
            {
                MessageBox.Show(_errorMessage);
            }
        }

        private void imageSuccess_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!string.IsNullOrEmpty(_url))
            {
                ProcessStartInfo start = new ProcessStartInfo(_url);
                start.UseShellExecute = true;
                Process.Start(start);
            }
        }
    }
}
